<?php
// +----------------------------------------------------------------------
// | 票付通资源库相关页面单入口文件
// +----------------------------------------------------------------------
// | Author: Guangpeng Chen <501468940@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/07/28
// +----------------------------------------------------------------------
// | www.12301.cc/module/pft_resource
// +----------------------------------------------------------------------
ob_start();
include("class/SimpleExcel.class.php");
define('ROOT_PATH', '/var/www/html/new/d/');
define('IN_PFT', true);
include_once ROOT_PATH . 'common/header.html';
include_once ROOT_PATH . 'common/left.html';
include_once ROOT_PATH . 'common/func.inc.php';

$method = isset($_REQUEST['m']) ? $_REQUEST['m']:'index';
if($method == 'index' || $method == 'add'){
    if($_SESSION['sid']!=1){
        header("Location://www.12301.cc/home.html");
    }
}

if($method=='index') {
    include ROOT_PATH . 'module/pft_resource/list.php';
    $out_html=ob_get_contents();
    ob_end_clean();
} elseif($method=='add') {
    include ROOT_PATH . 'tpl/pft_resource/add.html';
} elseif($method=='r') {
    include ROOT_PATH . 'tpl/pft_resource/resource.html';
} elseif($method=='edit') {
    include ROOT_PATH . 'module/pft_resource/edit.php';
} elseif ($method=='new') {
    include ROOT_PATH . 'tpl/pft_resource/repro.html';
}elseif ($method=='rep') {//发布产品

    $var['p_type'] = $_GET['type'];
    if($_GET['sid']+0>0){
        if($_SESSION['sdtype']!=9){
            if($_SESSION['dtype']==6 ) {
                if(\pft\Member\MemberAccount::GetMemType($_SESSION['sid'])!=0) {
                    exit('<script>alert("您的上级不是供应商身份，无法发布产品。")</script>');
                }
            }
            elseif($_SESSION['dtype']!=0) {
                exit('<script>alert("您不是供应商身份，无法发布产品。")</script>');
            }
            $sid = abs($_GET['sid']);
            if($sid){
                $sel_apply_did = "select apply_did from uu_land where id=$sid limit 1";
                $le->query($sel_apply_did);
                $row = $le->fetch_assoc();
                $apply_did = $_SESSION['dtype']==6? $_SESSION['sid'] : $_SESSION['memberID'];
                if($row['apply_did']!=$apply_did )
                    exit('<script>alert("这不是你的产品")</script>');
            }
        }elseif( !strpos($_SESSION['qx'],'upProd') && $_SESSION['memberID']!=1){
            exit('<script>alert("您无权访问这个页面")</script>');
        }

        $sql = "select * from uu_land where id={$_GET['sid']} limit 1";
        $GLOBALS['le']->query($sql);
        $var = $GLOBALS['le']->fetch_assoc();
        $var['sid'] = $_GET['sid'];
        $area = explode('|',$var['area']);
        if(is_array($area)){
            $var['area'] = '';
            if(in_array($area[0],array(1,2,3,4,32,33,34)))
                $area[1] = $area[0];
            foreach($area as $v){
                if($v=='0') break;
                $sql = "select area_name from uu_area where area_id in ($v) limit 1";
                $GLOBALS['le']->query($sql);
                $row = $GLOBALS['le']->fetch_assoc();
                $var['area'] .= "|".$row['area_name'];
            }
        }
        $var['area'] = ltrim($var['area'],'|');
        $sql = "select title from pft_resource where id={$var['resourceID']} limit 1";
        $GLOBALS['le']->query($sql);
        $GLOBALS['le']->fetch_assoc();
        $var['resource_title'] = $GLOBALS['le']->f('title');
        if(substr($var['jtype'],0,1)=='A'){
            $var['jtype'] = strlen($var['jtype']).'A';
        }
        if($var['jtype']>0){
            switch ($var['p_type']) {
            	case 'A':
                    $var['jtype'] .= 'A级';
            		break;
                case 'C':
                    $var['jtype'] .= '星级';
                    break;
            }
        }
        if($var['jtype']=='0') $var['jtype'] = '其它';

    }
    if(!$var['apply_did']) $var['apply_did'] = $_SESSION['sid'];
    if(!isset($var['terminal_type']) || $var['terminal_type']==1) $var['terminal_type']=1;
    include ROOT_PATH . 'tpl/pft_resource/rep.html';
}

if(isset($_REQUEST['Export']) && $_REQUEST['Export']=="Export"){
    $filename='资源库列表';
    $Excel[0]['title']='资源方名称';
    $Excel[0]['p_type']='资源类型';
    $Excel[0]['jtype']='资源级别';
    $Excel[0]['prov']='省';
    $Excel[0]['city']='市';
    $Excel[0]['address']='详细地址';
    $Excel[0]['lng_lat_pos']='经纬度';
    $Excel[0]['tel']='联系电话';
    $Excel[0]['runtime']='开放时间';
    $Excel[0]['topic']='主题';
    $Excel[0]['verify_status']='审核状态';
    $i=1;
    foreach($r as $lid=>$list){
        $n++;
        list($prov,$city) = explode('|',$list['area']);

        $Excel[$n]['title']  =$list['title'];
        $Excel[$n]['p_type'] =$ptypes[$list['p_type']];
        $Excel[$n]['jtype']  =$LevelList[$list['p_type']][$list['jtype']];
        $Excel[$n]['prov']   =$areas[$prov];
        $Excel[$n]['city']   =$areas[$city];
        $Excel[$n]['address']=$list['address'];
        $Excel[$n]['lng_lat_pos']=$list['lng_lat_pos'];
        $Excel[$n]['tel']    =$list['tel'];
        $Excel[$n]['runtime']=$list['runtime'];
        $Excel[$n]['topic']  =$list['topic'];
        $Excel[$n]['verify_status'] = $status_list[$list['verify_status']];
    }
//    echo '<pre>';
//    print_r($Excel);
//    echo '</pre>';
//    exit;
    $xls = new SimpleExcel('UTF-8', false,'orderList');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
    exit;
}
echo $out_html;
include_once ROOT_PATH . 'common/footer.html';

